<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/js/jquery-1.10.1.min.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>

<script type="text/javascript">
    $(document).ready(function(){

        /**
         * 修改付款方式
         */
        $(".status_").click(
            function(){
                var pre = 'status_';
                var num = $(this).attr('id').substr(pre.length);
                var id = $("#paywayid_"+num).text();
                var status = $("#status_"+num).text();
                var status_next = 0;
                if(status == 0)
                {
                    status_next = 1;
                }
                var data = {'id':id,'status_next':status_next};
                var re;
                $.ajax(
                    {
                        type:'post',
                        url:'<?php echo url::base(true)?>supplier/payway/changestatus',
                        dataType:'json',
                        data:data,
                        async:false,
                        success:function(re_data)
                        {
                            re = re_data;
                        },
                        error:function()
                        {
                            var error = new Object;
                            error.code = '8';
                            error.msg = "系统出错，请联系IT";
                            re = error;
                        }
                    }
                );

                alert(re.msg);
                if(re.code == 1)
                {
                    location.reload();
                }
            }
        );

        /**
         * 更改付款方式的名称
         *
         */
        $(".name_ok_").click(function(){
            var pre = 'name_ok_';
            var num = $(this).attr('id').substr(pre.length);
//            var id = parseInt($("#paywayid_"+num).text());
            var id = parseInt($("#id_"+num).val());
            var name = $("#name_input_"+num).val();
            var re;
            $.ajax(
                {
                    type:'post',
                    url:'<?php echo url::base(true)?>supplier/payway/changename',
                    dataType:'json',
                    data:{'id':id,'paywayname':name},
                    async:false,
                    success:function(re_data)
                    {
                        re = re_data;
                    },
                    error:function()
                    {
                        var error = new Object;
                        error.code = '8';
                        error.msg = "系统出错，请联系IT";
                        re = error;
                    }
                }
            );

            alert(re.msg);
            if(re.code == 1)
            {
                location.reload();
            }
        });

        $(".name_edit_").click(function(){
            var pre = 'name_edit_';
            var num = $(this).attr('id').substr(pre.length);
            $("#showdiv_"+num).hide();
            $("#changediv_"+num).show();
        });

        $(".name_cancel_").click(function(){
            var pre = 'name_cancel_';
            var num = $(this).attr('id').substr(pre.length);
            $("#showdiv_"+num).show();
            $("#changediv_"+num).hide();
        });

        $("#status_select").change(function(){
            $("#status_form").submit();
        });

    })
</script>

<form action="<?php echo url::base(true)?>supplier/payway/add" method="post">
    添加付款方式<input type="text" name="paywayname">
    <input type="submit" value="添加" >
</form>
<form action="<?php echo url::base(true)?>supplier/payway/index" method="post" id="status_form">
   <!-- 状态
    <select id="status_select" name="status">
        <option value="all">
        全部
        </option>
        <option value="0" <?php /*if(isset($status_select) and $status_select == 0){ echo 'selected="selected"';}*/?>>
        激活
        </option>
        <option value="1" <?php /*if(isset($status_select) and $status_select == 1){ echo 'selected="selected"';}*/?>>
        停用
        </option>
    </select>-->
</form>

<table class="table table-hover ">
    <tr>
        <th>编号</th>
        <th>名称</th>
<!--        <th>状态</th>-->

    </tr>
    <?php
    if(isset($payway_lists))
    foreach($payway_lists as $num => $payway)
    {{?>
<tr>
        <th >
            <div id="paywayid_<?php echo $num+1;?>">
                <?php echo isset($payway['id'])?$payway['id']:""?>
            </div>
        </th>
        <th>
            <div id="showdiv_<?php echo $num+1?>">
            <?php echo isset($payway['paywayname'])?$payway['paywayname']:""?>
            <button id="name_edit_<?php echo $num+1;?>" class="name_edit_"  style="display: none">修改</button>
            </div>

            <div id="changediv_<?php echo $num+1?>" style="display: none">
            <input type="hidden" id="id_<?php echo $num+1;?>" value="<?php echo isset($payway['id'])?$payway['id']:""?>">
            <input type="text" id="name_input_<?php echo $num+1;?>" class="name_input"
                   value="<?php echo isset($payway['paywayname'])?$payway['paywayname']:""?>">
            <button id="name_ok_<?php echo $num+1;?>" class="name_ok_" >
                确定</button>
            <button id="name_cancel_<?php echo $num+1;?>" class="name_cancel_"  >取消</button>
            </div>
        </th>
        <!--<th>
            <span id="status_<?php /*echo $num+1 */?>" style="display: none">
            <?php /*echo isset($payway['status'])?$payway['status']:"2"*/?>
            </span>
            <?php /*echo isset($payway['status_string'])?$payway['status_string']:""*/?>
            <button id="status_<?php /*echo $num+1;*/?>" class="status_">
                修改状态
            </button>
        </th>-->

        </tr>
    <?php } }?>
</table>